package com.ethink.platform.controller.warehouse;

import com.ethink.framework.common.web.BaseController;
import com.ethink.framework.common.web.response.CommonResponse;
import com.ethink.warehouse.api.MatePurchaseCodeFacade;
import com.ethink.warehouse.api.info.MatePurchaseCodeInfo;
import com.ethink.warehouse.api.request.MatePurchaseCodeQueryRequest;
import com.ethink.warehouse.api.request.MatePurchaseCodeUpdateRequest;
import com.ethink.warehouse.api.response.MatePurchaseCodeGetDetailResponse;
import com.ethink.warehouse.api.response.MatePurchaseCodeQueryResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 库存采购批次表 Controller
 *
 * @author default
 * @date 2022-12-16
 */
@Tag(name = "MatePurchaseCodeController", description = "库存采购批次表 Controller")
@RestController
@Slf4j
@RequestMapping("platform-server/v1/warehouse-service")
public class MatePurchaseCodeController extends BaseController {

    @Autowired
    private MatePurchaseCodeFacade matePurchaseCodeFacade;

    @Operation(summary = "根据生产批次获取最新采购批次")
    @GetMapping("/matePurchaseCode/getByProduceCode")
    public CommonResponse<MatePurchaseCodeInfo> getMatePurchaseCodeByProduceCode(
            @RequestParam("mateSku") String mateSku,
            @RequestParam("produceCode") String produceCode) {
        return succeedWith(matePurchaseCodeFacade.getMatePurchaseCodeByProduceCode(mateSku, produceCode));
    }

    @Operation(summary = "根据生产批次获取最新采购批次")
    @GetMapping("/matePurchaseCode/getListByProduceCode")
    public CommonResponse<List<MatePurchaseCodeInfo>> getMatePurchaseCodeListByProduceCode(
            @RequestParam("mateSku") String mateSku,
            @RequestParam("excludeProduceCode") String excludeProduceCode) {
        return succeedWith(matePurchaseCodeFacade.getMatePurchaseCodeListByProduceCode(mateSku, excludeProduceCode));
    }

    @Operation(summary = "分页查询")
    @GetMapping("/matePurchaseCode/query")
    public CommonResponse<List<MatePurchaseCodeQueryResponse>> queryMatePurchaseCode(MatePurchaseCodeQueryRequest request) {
        return succeedWithPage(matePurchaseCodeFacade.queryMatePurchaseCode(request));
    }

    @Operation(summary = "详情查询")
    @GetMapping("/matePurchaseCode/get/{matePurchaseCodeId}")
    public CommonResponse<MatePurchaseCodeGetDetailResponse> getMatePurchaseCodeById(@PathVariable("matePurchaseCodeId") Long matePurchaseCodeId) {
        return succeedWith(matePurchaseCodeFacade.getMatePurchaseCodeById(matePurchaseCodeId));
    }

    @Operation(summary = "更新")
    @PutMapping("/matePurchaseCode/update")
    public CommonResponse updateMatePurchaseCode(@RequestBody @Validated MatePurchaseCodeUpdateRequest request) {
        matePurchaseCodeFacade.updateMatePurchaseCode(request);
        return succeed();
    }

}